package com.ifreshwing.activity.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TextInputEditText;
import android.widget.Button;
import android.widget.TextView;

import com.ifreshwing.activity.MainActivity;
import com.ifreshwing.userpark.R;
import com.ifreshwing.utils.SharedPreferencesUtil;
import com.ifreshwing.utils.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lz on 2017/4/27.
 */

public class LoginActivity extends BaseActivity {
    @BindView(R.id.titleBar_text)
    TextView titleBarText;
    @BindView(R.id.et_account)
    TextInputEditText etAccount;
    @BindView(R.id.et_password)
    TextInputEditText etPassword;
    @BindView(R.id.btn_login)
    Button btnLogin;
    @BindView(R.id.coorLayout)
    CoordinatorLayout coordinatorLayout;
    private boolean isLogin = false;
    Context context;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        titleBarText.setText("登录");
        context = this;
        isLogin = SharedPreferencesUtil.isLogin(context);
        if (isLogin) {
            startActivity(MainActivity.class);
        }
    }

    @OnClick(R.id.btn_login)
    public void onViewClicked() {
        if (etAccount.getText().toString().isEmpty()) {
            ToastUtil.longToast(context, "请输入账号");
            return;
        }
        if (etPassword.getText().toString().isEmpty()) {
            ToastUtil.longToast(context, "请输入密码");
            return;
        }
        SharedPreferencesUtil.setIsLogin(this, true);
        startActivity(MainActivity.class);
        ToastUtil.longToast(context, "登录成功");
        finish();
    }

}
